package com.example.myapplication.HomeAdapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.HomeActivity.HomeGridViewActity;
import com.example.myapplication.HomeBean.HomeGridViewBean;
import com.example.myapplication.R;
import com.example.myapplication.WuChangFuBenActivity.WuChangFuBen;

import java.util.ArrayList;
import java.util.List;

public class HomeGridViewAdapter extends BaseAdapter {
    List<HomeGridViewBean> list=new ArrayList<>();
    Activity activity;
    Context context;

    public HomeGridViewAdapter(List<HomeGridViewBean> list, Activity activity,Context context) {
        this.list = list;
        this.activity = activity;
        this.context=context;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view= LayoutInflater.from(activity).inflate(R.layout.home_gv_mokuai,null);
        ImageView img=view.findViewById(R.id.Home_gv_img);
        TextView name=view.findViewById(R.id.Home_gv_text);
        img.setImageResource(list.get(i).getImg());
        name.setText(list.get(i).getName());

        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (i){
                    case 0:
                        TiaoZhuan();
                        Toast.makeText(activity,"1",Toast.LENGTH_LONG).show();
                        break;
                    case 1:
                        TiaoZhuan();
                        Toast.makeText(activity,"2",Toast.LENGTH_LONG).show();
                        break;
                    case 2:
                        TiaoZhuan();
                        Toast.makeText(activity,"3",Toast.LENGTH_LONG).show();
                        break;
                    case 3:
                        TiaoZhuan();
                        Toast.makeText(activity,"4",Toast.LENGTH_LONG).show();
                        break;
                    case 4:
                        TiaoZhuan();
                        Toast.makeText(activity,"5",Toast.LENGTH_LONG).show();
                        break;
                }
            }

            private void TiaoZhuan() {
                Intent intent=new Intent(context, HomeGridViewActity.class);
                Bundle bundle=new Bundle();
                bundle.putString("name",list.get(i).getName());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });


        return view;
    }


}
